package com.tavenli.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tavenli.entity.UserEntity;
import com.tavenli.model.PageData;
import com.tavenli.services.UCenterService;
import com.tavenli.services.UResourceService;
import com.tavenli.utils.PageNavUtil;

@Controller
@RequestMapping("/u")
public class UArticleController extends UBaseController{
	private static Logger logger = LoggerFactory.getLogger(USysController.class);
	@Autowired
	private UCenterService uCenterService;	
	@Autowired
	private UResourceService uResourceService;
	
	@RequestMapping("/classes")
	public String userList(Model model,Integer page,String userName) {
		
		page = page== null ? 1 : page<1 ? 1 : page;
		
		int pageSize = 10;
		
		PageData<UserEntity> pageData = this.uCenterService.getArticleClasses(page, pageSize, userName);
		
		model.addAttribute("dataList", pageData.getPageData());
		model.addAttribute("totalCount", pageData.getTotalCount());
		model.addAttribute("totalPage", pageData.getTotalPage());
		model.addAttribute("currentPage", page);
		model.addAttribute("pageNav", PageNavUtil.getPageNavHtml(page.intValue(), pageSize, pageData.getTotalCount(), 15));
		
		return "ucenter/article/classesList";
	}
	
	/*@RequestMapping("/userAdd")
	public String userAdd(Model model,UserEntity userEntity) {
		userEntity.setStatus(1);
		model.addAttribute("userEntity", userEntity);
		return "ucenter/sys/userEdit";
	}
	
	@RequestMapping("/userEdit")
	public String userEdit(Model model,int id) {
		
		UserEntity userEntity = this.uCenterService.getUser(id);
		model.addAttribute("userEntity", userEntity);
		return "ucenter/sys/userEdit";
	}*/
}
